<?php

declare(strict_types=1);

namespace App\Controller;

use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Redis\Redis;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Trait\ResponseMsg;
use App\Model\Normal;
use Hyperf\Di\Annotation\Inject;
use function Hyperf\ViewEngine\view;
use Hyperf\Guzzle\ClientFactory;
use Hyperf\Utils\FileSystem\FileSystem;
use Psr\Http\Message\ResponseInterface;

use Util\Common;
use function PHPUnit\Framework\throwException;
use  App\Services\FileService;


class UploadController extends AbstractController
{

    use ResponseMsg;

    protected Redis $redis;
    protected Normal $normal;
    protected FileService $service;

    public function __construct()
    {
        $this->redis = container()->get(Redis::class);
        $this->normal = container()->get(Normal::class);
        $this->service = container()->get(FileService::class);
    }

    /**
     * @param RequestInterface $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function baseImg(RequestInterface $request):ResponseInterface{
        $inputData = $request->file('file');
        $data = $this->service->uploadImg($inputData);
        return $this->success(data:$data,msg:'上传成功');
    }

    /**
     * @param RequestInterface $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function backImg(RequestInterface $request):ResponseInterface{
        $inputData = $request->file('file');
        $data = $this->service->backImg($inputData);
        return $this->success(data:$data,msg:'上传成功');
    }

}
